export const treeDataAdaptive = (treeData, { key, title, children }) => {
    if (!treeData || (Array.isArray(treeData) && treeData.length === 0)) {
        return [];
    }
    return (treeData || []).map((item) => ({
        key: item[key],
        title: item[title],
        scopedSlots: { title: "title" },
        selectable: true,
        children: treeDataAdaptive(item[children], { key, title, children }),
    }));
};
export const getFlatData = (data) => {
    if (!data || (Array.isArray(data) && data.length === 0)) {
        return [];
    }
    let flatAry = [];
    data.forEach((item) => {
        flatAry.push({ key: item.key, title: item.title });
        flatAry = flatAry.concat(getFlatData(item.children));
    });
    return flatAry;
};
export const getParentKey = (key, tree) => {
    let parentKey;
    for (let i = 0; i < tree.length; i++) {
        const node = tree[i];
        if (node.children) {
            if (node.children.some((item) => item.key === key)) {
                parentKey = node.key;
            } else if (getParentKey(key, node.children)) {
                parentKey = getParentKey(key, node.children);
            }
        }
    }
    return parentKey;
};
